/proc/xen/xsd_kva exports mmap interface that xenstored now uses to map the
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 3 Mar 2006 18:07:55 +0000 (19:07 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 3 Mar 2006 18:07:55 +0000 (19:07 +0100)
domain0 xenbus page.

Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
tools/xenstore/xenstored_domain.c

index cab6d5bec8e34fd5f5853c18ef397c57d91b948b..0448f18f0a856ebc93cfaed268cf1e6beee2254d 100644 (file)
@@ -951,9 +951,25 @@ void xenbus_probe(void *unused)
 }
 
 
+static struct file_operations xsd_kva_fops;
 static struct proc_dir_entry *xsd_kva_intf;
 static struct proc_dir_entry *xsd_port_intf;
 
+static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       size_t size = vma->vm_end - vma->vm_start;
+
+       if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
+               return -EINVAL;
+
+       vma->vm_pgoff = mfn_to_pfn(xen_start_info->store_mfn);
+
+       if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+                           size, vma->vm_page_prot))
+               return -EAGAIN;
+
+       return 0;
+}
 
 static int xsd_kva_read(char *page, char **start, off_t off,
                         int count, int *eof, void *data)
@@ -1027,9 +1043,14 @@ static int __init xenbus_probe_init(void)
                xen_start_info->store_evtchn = op.u.alloc_unbound.port;
 
                /* And finally publish the above info in /proc/xen */
-               if((xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0400)))
+               if ((xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0400))) {
+                       memcpy(&xsd_kva_fops, xsd_kva_intf->proc_fops,
+                              sizeof(xsd_kva_fops));
+                       xsd_kva_fops.mmap = xsd_kva_mmap;
+                       xsd_kva_intf->proc_fops = &xsd_kva_fops;
                        xsd_kva_intf->read_proc = xsd_kva_read;
-               if((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400)))
+               }
+               if ((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400)))
                        xsd_port_intf->read_proc = xsd_port_read;
        }
 
index 563f07e596f177e650012545fcb983470a2ff4fd..27f906dda6a8814e9cc803ea0bbe465178242c49 100644 (file)
@@ -27,7 +27,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <paths.h>
 
 //#define DEBUG
 #include "utils.h"
@@ -466,22 +465,9 @@ static int dom0_init(void)
 { 
        int rc, fd;
        evtchn_port_t port; 
-       unsigned long kva; 
        char str[20]; 
        struct domain *dom0; 
 
-       fd = open(XENSTORED_PROC_KVA, O_RDONLY); 
-       if (fd == -1)
-               return -1;
-
-       rc = read(fd, str, sizeof(str)); 
-       if (rc == -1)
-               goto outfd;
-       str[rc] = '\0'; 
-       kva = strtoul(str, NULL, 0); 
-
-       close(fd); 
-
        fd = open(XENSTORED_PROC_PORT, O_RDONLY); 
        if (fd == -1)
                return -1;
@@ -496,12 +482,12 @@ static int dom0_init(void)
 
        dom0 = new_domain(NULL, 0, port); 
 
-       fd = open(_PATH_KMEM, O_RDWR);
+       fd = open(XENSTORED_PROC_KVA, O_RDWR);
        if (fd == -1)
                return -1;
 
        dom0->interface = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
-                              MAP_SHARED, fd, kva);
+                              MAP_SHARED, fd, 0);
        if (dom0->interface == MAP_FAILED)
                goto outfd;